<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Http\Exceptions\HttpResponseException;

class ReportRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            // 'platform_id' => ['required', 'exists:platforms,id'],
            'platform_user_id' => ['required', 'string'],
            'type' => ['required', 'string'],
            'content' => ['required', 'string', 'max:1000'],
            'evidence' => ['nullable', 'array'],
            'evidence.*' => ['url'],
            // 'severity_level' => ['required', Rule::in(['low', 'medium', 'high', 'critical'])],
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages(): array
    {
        return [
            'platform_id.required' => '平台ID不能为空',
            'platform_id.exists' => '所选平台不存在',
            'platform_user_id.required' => '平台用户ID不能为空',
            'type.required' => '举报类型不能为空',
            'content.required' => '举报内容不能为空',
            'content.max' => '举报内容不能超过1000个字符',
            'evidence.array' => '证据必须是数组格式',
            'evidence.*.url' => '证据链接格式不正确',
            'severity_level.required' => '严重程度不能为空',
            'severity_level.in' => '严重程度必须是 low、medium、high 或 critical',
        ];
    }

    /**
     * Handle a failed validation attempt.
     *
     * @param  \Illuminate\Contracts\Validation\Validator  $validator
     * @return void
     *
     * @throws \Illuminate\Validation\ValidationException
     */
    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'success' => false,
            'message' => '验证失败',
            'errors' => $validator->errors()
        ], 422));
    }
} 